package com.thiswhyme.redis.lock.helper;

import com.thiswhyme.redis.lock.DistributedLock;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @description: 测试demo
 *
 * @author: thiswhyme
 * @date: 2022/10/26
 */
@Slf4j
@Service
public class DemoService {

    private int count = 0;

    @DistributedLock(keyPrefix = "doAdd1", key = {"#p0", "#input2"})
    public void doAdd1(String input1, String input2) {
        Sleeper.sleep(1, TimeUnit.SECONDS);
        count++;
        log.info("======= doAdd1:" + count);
    }

    @DistributedLock(key = "#input")
    public void doAdd2(String input) {
        Sleeper.sleep(1, TimeUnit.SECONDS);
        count++;
        System.out.println("======= doAdd2:" + count);
    }
}
